<template>
	<view class="container">
		<view class="tabs">
			<u-tabs :list="list" scrollable=false lineWidth="30" :current='current' lineColor="#f56c6c" @change="change"
				:activeStyle="{
									color: '#303133',
									fontWeight: 'bold',
									transform: 'scale(1.05)'
								}" :inactiveStyle="{
									color: '#606266',
									transform: 'scale(1)'
								}" itemStyle="padding-left: 15px; padding-right: 15px; height: 34px;">
			</u-tabs>
		</view>
		<view class="tablist">
			<block v-for="(item, index) in showcommentlist">
				<view class="comment" :key='index'>
					<view class="left">
						<image :src="item.userInfo.avatarUrl" mode=""></image>
					</view>
					<view class="right">
						<view class="top">
							<view class="name">{{ item.userInfo.nickName }}</view>
						</view>
						<view class="image">
							<image :src="item.picList" mode="" v-show="Boolean(item.picList.length)"></image>
						</view>
						<view class="content">{{ item.content }}</view>
						<view class="buttom" >{{ item.addTime }}</view>
					</view>
				</view>
			</block>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [{
					name: '全部评论',
					badge: {
						// isDot: true,
						// value:5
					}
				}, {
					name: '图片评论',
					badge: {
						// isDot: true
					}
				}],
				id: null, //商品id
				current: 0 ,//标签下标
				showcommentlist:[],
				show:false
			}
		},
		methods: {
			//切换评论
			change(e) {
				this.current = e.index
				this.showcommentlist=[]
				this.$get(this.API.comment, {
					type: 0,
					valueId: this.id,
					showType: e.index
				}).then(res => {
					this.list[e.index].badge.value=res.data.data.total
					this.getfor(res.data.data.page,res.data.data.pages,this.id,e.index)
				})
			},
			//评论列表
			getCommentList(id){
				this.id=id
				this.$get(this.API.comment, {
					type: 0,
					valueId:id,
					showType: this.current
				}).then(res => {
					console.log(res.data)
					this.list[this.current].badge.value=res.data.data.total
					this.getfor(res.data.data.page,res.data.data.pages,id,this.current)
					
				})
			},
			getfor(page,pages,id,index){
				for (let i = page; i <=pages; i++) {
					this.$get(this.API.comment, {
						type: 0,
						valueId:id,
						showType: index,
						page: i
					}).then(res=>{
				this.showcommentlist=this.showcommentlist.concat(res.data.data.list)
					})
				}
			}
		},
		onLoad(option) {
			this.id = option.id
			this.getCommentList(option.id)
			
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		.tablist {
			.comment {
				display: flex;
				margin-bottom: 40rpx;

				.left {
					image {
						width: 64rpx;
						height: 64rpx;
						border-radius: 50%;
						background-color: #f2f2f2;
					}
				}

				.right {
					flex: 1;
					padding-left: 20rpx;
					font-size: 30rpx;

					.top {
						// display: flex;
						justify-content: space-between;
						align-items: center;
						margin-bottom: 10rpx;

						.name {
							color: #5677fc;
						}
					}
					.buttom{
						font-size: 25rpx;
					}
				}
			}
		}
	}
</style>
